package com.dragon.wangyiwork.controller;

import cn.hutool.core.util.ObjectUtil;
import com.dragon.wangyiwork.entity.Commodity;
import com.dragon.wangyiwork.entity.User;
import com.dragon.wangyiwork.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class PageController {

    @Autowired
    private CommodityService commodityService;

    @RequestMapping(value = "/",method = {RequestMethod.GET,RequestMethod.POST})
    public String defaultPath(Model model,Integer type) {
        if(type==null) {
            List<Commodity> commodityList = commodityService.getAllCommodity();
            model.addAttribute("commodityList", commodityList);
            return "index";
        }else {
            List<Commodity> notBuyCommodity = commodityService.getNotBuyCommodity();
            model.addAttribute("commodityList",notBuyCommodity);
            return "indexNotBuy";
        }

    }



}
